package com.gusto.samples.movielens;

import org.apache.log4j.Logger;

import com.gusto.engine.semsim.neighborhood.storedistance.URLToID;

public class MovieLensURLToID implements URLToID {
	
	private static Logger log = Logger.getLogger(MovieLensURLToID.class);
	
	public String transformURLToId(String resourceUrl) {
		String id = "";
		if (resourceUrl.contains("#M_")) {
			id = resourceUrl.substring(resourceUrl.lastIndexOf("#M_") + 3);
		}
		else if (resourceUrl.contains("#_")) {
			id = resourceUrl.substring(resourceUrl.lastIndexOf("#_") + 2);
		}
		try {
			log.debug("Transform URI to LongId " + resourceUrl + " -> " + id);
			return id;
		}
		catch (Exception ex) {
			log.error("Transformation error " + ex + " -> null");
			return null;
		}
	}
	
}
